<div class="span3">
    <div class="well sidebar-nav">
        <ul class="nav nav-list">
            <li class="nav-header"><?php echo __('Actions'); ?></li>
            <li><?php echo $this->Html->link(__('New Image'), array('action' => 'add')); ?></li>
            <li><?php echo $this->Html->link(__('List Products'), array('controller' => 'products', 'action' => 'index')); ?> </li>
            <li><?php echo $this->Html->link(__('New Product'), array('controller' => 'products', 'action' => 'add')); ?> </li>
        </ul>
    </div>
</div>

<div class="span9">
    <?php echo $this->Session->flash(); ?>
    <div class="page-header">
        <h1>Imagenes</h1>
    </div>

    <table class="table table-bordered table-striped">
        <thead>
            <th><?php echo $this->Paginator->sort('product_id', 'Producto'); ?></th>
            <th><?php echo $this->Paginator->sort('filename', 'Titulo'); ?></th>
            <th><?php echo $this->Paginator->sort('filepath', 'Img'); ?></th>
            <th><?php echo $this->Paginator->sort('type', 'Tipo'); ?></th>
            <th><?php echo $this->Paginator->sort('is_active', 'Activa'); ?></th>
            <th><?php echo $this->Paginator->sort('is_front', 'Principal'); ?></th>
            <th colspan="3"><?php echo __('Actions'); ?></th>
            </tr>
        </thead>
        <tbody>    
    <?php foreach ($images as $image): ?>
        <?php 
        
        if (!empty($image['Image']['filepath'])) {
            $img = $this->Html->url(h($image['Image']['filepath']), true );
            $this->Fancybox->setProperties( array( 
                'class' => 'fancybox3',
                'className' => 'fancybox.image',
                'title'=> h($image['Image']['filename']),
                'rel' => 'gallery1'
                )
            );  
            $this->Fancybox->setPreviewContent('Ver');
            $this->Fancybox->setMainContent($img); 
            $fancybox = $this->Fancybox->output();
        }
        ?>
    <tr>
        <td>
            <?php echo $this->Html->link($image['Product']['title'], array('controller' => 'products', 'action' => 'view', $image['Product']['id'])); ?>
        </td>
        <td><?php echo h($image['Image']['filename']); ?>&nbsp;</td>
        <td><?php echo isset($fancybox) ? $fancybox : ''; ?>&nbsp;</td>
        <td><?php echo h($image['Image']['type']); ?>&nbsp;</td>
        <td><?php echo (h($image['Image']['is_active'])) ? 'si' : 'no'; ?>&nbsp;</td>
        <td><?php echo (h($image['Image']['is_front'])) ? 'si' : 'no'; ?>&nbsp;</td>        
        <td>
            <?php echo $this->Html->link(__('View'), array('action' => 'view', $image['Image']['id']), array('class' => 'btn btn-info')); ?>
        </td>
        <td>
            <?php echo $this->Html->link(__('Edit'), array('action' => 'edit', $image['Image']['id']), array('class' => 'btn btn-warning')); ?>
        </td>
        <td>
            <?php echo $this->Form->postLink(__('Delete'), array('action' => 'delete', $image['Image']['id']), array('class' => 'btn btn-danger'), __('Are you sure you want to delete # %s?', $image['Image']['id'])); ?>
        </td>
    </tr>
<?php endforeach; ?>
</tbody>
    </table>
    
<div class="well">
        <?php echo $this->Paginator->counter(array('format' => __d('cake', 'Page {:page} of {:pages}, showing {:current} records out of {:count} total, starting on record {:start}, ending on {:end}'))); ?>
    </div>
    <?php if ($this->Paginator->numbers()): ?>
        <div class="pagination">
            <ul>
                <?php echo $this->Paginator->first(); ?>
                <?php echo $this->Paginator->prev(); ?>
                <?php echo $this->Paginator->numbers(); ?>
                <?php echo $this->Paginator->next(); ?>
                <?php echo $this->Paginator->last(); ?>
            </ul>
        </div>
    <?php endif ?>
</div>
